package com.zzb.framework.modules.job.log;

import com.zzb.framework.common.BaseResponse;
import com.zzb.framework.modules.event.AbstractProcessor;
import com.zzb.framework.modules.param.entity.SysParam;
import com.zzb.framework.modules.param.event.SysParamChangeEvent;
import com.zzb.framework.utils.ConfigConstant;
import org.springframework.stereotype.Service;

/**
 * 日志地址变更监视器
 */
@Service("logPathChangeObserver")
public class LogPathChangeObserver implements AbstractProcessor<SysParamChangeEvent> {
    @Override public BaseResponse execute(SysParamChangeEvent event) {
        SysParam sysParam = event.getSysParam();
        if (sysParam.getParamKey().equalsIgnoreCase(ConfigConstant.JOB_LOG_FILE_PATH) ||
                sysParam.getParamKey().equalsIgnoreCase(ConfigConstant.JOB_GLUE_FILE_PATH)) {
            //重新初始化目录
            XxlJobFileAppender.initLogPath();
        }
        return BaseResponse.ok();
    }
}
